iT邦幫忙

2024 iThome 鐵人賽

DAY 5
0

今天來解YKL04(UVA10071):Back to High School Physics 和 YKL05(UVA11150):Cola

Back to High School Physics

https://ithelp.ithome.com.tw/upload/images/20240919/20155574h3doH4HEEV.png

重點 double of that time
2 * v * t

#include <iostream>
using namespace std;

int main(){
	int v,t;
	while(cin >> v >> t){
		cout << 2 * v * t << endl;
	}
	return 0;
}

Cola

https://ithelp.ithome.com.tw/upload/images/20240919/20155574YF1lE676xM.png

https://ithelp.ithome.com.tw/upload/images/20240919/201555745qaIrsopkV.png

一種是不借空瓶,另一種是借空瓶,然後取兩者中的最大值。
-先記錄購買的coke數量
-兌換:空瓶大於3個時
用空瓶兌換coke(3個空瓶換1瓶新的coke)
更新喝到的coke數量
更新空瓶數量(喝完新的coke加上剩下的空瓶)
-借瓶:
當空瓶數剩下2時,向別人借1個空瓶,並換一瓶新的,最後更還

方法1

#include <iostream>
using namespace std;
int main(){
    int n;
    while (cin >> n) {
        int total = n;    
        int empty = n;    

        while (empty >= 3) {
            int newCola = empty / 3;  
            total += newCola;         
            empty = empty % 3 + newCola;  
        }
        if (empty == 2) {
            total++;
        }
        cout << total << endl; 
    }
    return 0;
}

方法2

#include <iostream>
using namespace std;

int main(){
    int n;
    while(cin >> n){
        cout << n + n / 2 << endl;
    }
    return 0;
}

上一篇
CPE C++ 刷題 Day 4
下一篇
CPE C++ 刷題 Day 6
系列文
CPE C++ 刷題20
圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

尚未有邦友留言

立即登入留言